<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { propApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray } from '@/utils'
  import Pagination from "@/components/Pagination/index.vue";
  import xmDatePicker from '@/components/xmDatePicker/index.vue';
  const action = reactive({
    timeObj:getPlayEndTime(getDateArray('ymdhis')),
    total:0,
    list:[] as any[],
  })
  const initialQuery = {
    page: 1,
    limit: 20,
    uuid: null,
    goods_id: null,
  }
  const listQuery = reactive({
    ...initialQuery
  })
  const handleSerach = () => {
    listQuery.page = 1;
    getList();
  };
  const resetQuery = () => {
    action.timeObj = getPlayEndTime(getDateArray('ymdhis'))
    Object.assign(listQuery, {
      ...initialQuery
    });
    getList()
  };
  const getList = async()=> {
    const loading = Toastloading()
    const { playTime:begin_date = '', endTime:end_date='' } = action.timeObj
    if(!listQuery.uuid) listQuery.uuid = null
    if(!listQuery.goods_id) listQuery.goods_id = null
    const res = await propApi.getGoodsShopLog({
      begin_date,
      end_date,
      ...listQuery
    })
    loading.close()
    const { data=[], total=0, } = res?.data || {}
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <el-input v-model="listQuery.uuid" placeholder="请输入用户UUID"/>
        </div>
        <div class="labelItem">
          <div class="label">商品ID：</div>
          <el-input v-model="listQuery.goods_id" placeholder="请输入商品ID"/>
        </div>
        <xmDatePicker v-model:timeval="action.timeObj" />
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border
    >
      <el-table-column width="120" prop="uuid" label="用户UUID" />
      <el-table-column min-width="180" show-overflow-tooltip prop="nickname" label="用户昵称" />
      <el-table-column width="120" prop="goods_id" label="商品ID" />
      <el-table-column min-width="180" prop="goods_name" label="商品名称" />
      <el-table-column width="120" prop="time_limit" label="购买期限(天)" />
      <el-table-column min-width="180" prop="end" label="当前商品过期时间" />
      <el-table-column min-width="180" prop="create_time" label="创建时间" />
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
  </div>
</template>